'''Module responsible for measuring statistics on the current machine.'''
import measure
stats = {#'hostname':measure.hostname,
         'disk':measure.disk_space, 
         'uptime':measure.uptime,
         'load':measure.cpu_load,
	   '#cores':measure.num_cores,
	   '#cpus':measure.num_cpus,
	   'avg_cpu_freq':measure.avg_cpu_freq,
	  # 'boot_time':measure.boot_time, // does not work on their machines :(
	   'memory':measure.memory,
	   'java':measure.java,
       'num_java_procs':measure.num_java_running}

cache = {} #

def gather():
    '''Gathers statistics about current machine. 

Returns a dictionary of key:value pairs. Keys are strings indicating type of 
statistic, values are string data. First call to the function will gather all
possible stats: successive ones will only return stats that changed since the
last call.
    '''
    results = {}

    for name in stats:
        try:
            # measure statistic
            value = str(stats[name]())
            # check if it changed, move on to next statistic if it didn't
            if name in cache:
                if cache[name]==value: continue 
            # record statistic
            results[name] = cache[name] = value
        except:
            print 'Exception while trying to measure:',name

    return results

